/**
 * 订单管理 交易订单
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户积分明细</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">

      <el-form-item label="搜索：">
        <el-input size="small" v-model="userKey" placeholder="输入用户名/手机号"></el-input>
      </el-form-item>
      <!-- <el-form-item>
        <el-select size="small" v-model="status" placeholder="请选择">
          <el-option v-for="type in payType" :label="type.key" :value="type.value" :key="type.value"></el-option>
        </el-select>
      </el-form-item> -->

      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="getIntegralList(1)">搜索</el-button>
      </el-form-item>

      
      <download-excel
          class = "export-excel-wrapper"
          :data = "fileList"
          :fields = "fieldsList"
          name = "用户积分明细.xls">
          <!-- 上面可以自定义自己的样式，还可以引用其他组件button -->
          <el-button type="primary" size="small">导出EXCEL</el-button>
      </download-excel>


    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border
      element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column prop="id" label="id" width="60">
      </el-table-column>

 
      <el-table-column sortable prop="mobile" label="用户手机号" width="200">
        <template slot-scope="scope">
          <div v-if="scope.row.userEntity">{{scope.row.userEntity.mobile}}</div>

        </template>
      </el-table-column>

      <el-table-column sortable prop="number" label="积分数量" width="100">
      </el-table-column>
      
      <el-table-column sortable prop="type" label="支出/收入" width="140" show-overflow-tooltip>
        <template slot-scope="scope">
          <div v-if="scope.row.status == 0">支出</div>
          <div v-if="scope.row.status == 1">收入</div>
        </template>
      </el-table-column>

      <el-table-column sortable prop="title" label="备注" width="100">
      </el-table-column>
  


      <el-table-column sortable prop="addTime" label="创建时间" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <div>{{ transformDate(scope.row.creation_time) }}</div>
        </template>
      </el-table-column>

    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>

  </div>
</template>

<script>
import { getIntegralList } from '../../api/userMG'
import Pagination from '../../components/Pagination'
export default {
  data() {
    return {
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '预览',

      userKey: "",
      status: 0,

      
      formInline: {
        page: 1,
        limit: 10,
        machineNo: '',
        orderNo: '',
        transId: '',
        payType: 0,
        orderStatus: 0,
        token: localStorage.getItem('logintoken')
      },

      listData: [], //用户数据
      pageparm: {
        currentPage: 1,
        pageSize: 20,
        total: 10
      },


       // 导出Excel 字段
       fieldsList: {
        "id": "id",    //常规字段
        "手机号":"mobile",
        "积分数量":"number",
        "备注":"title",
        "状态":"status",
        "创建时间":"creation_time"

      },
      fileList:[],


    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.getIntegralList(1)


  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    getMainImg(goodsData) {

      return JSON.parse(JSON.parse(goodsData).carousel)[0];

    },
    // 获取订单列表
    getIntegralList(page) {
      this.loading = true;
      var parameter = {
        mobile: this.userKey,
        type: 0,
        page: (page - 1) * 20,
      };
      getIntegralList(parameter).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          this.listData = res.data.data;
          this.pageparm.currentPage = page;
          this.pageparm.total = res.data.count;



          var fileList = []

          for (let index = 0; index <  this.listData.length; index++) {
            const element =  this.listData[index];

            var statusName = "";

            if (element.status == 0) {
              statusName =  "支出"
            }
            if (element.status == 1) {
              statusName =  "收入"
            }
     


            var creation_time = this.transformDate(element.creation_time) ;
    


            var item = {
              id:element.id,//id
              mobile:element.userEntity.mobile,//用户手机号
              number:element.number,//积分数量
              title:element.title,//备注
              status:statusName,//状态
              creation_time:creation_time,//创建时间

            }
            

            fileList.push(item)



          }

          this.fileList = fileList;






          return;
        }
        this.$message({
          type: "info",
          message: res.msg,
        });
      });
    },

    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getIntegralList(this.formInline.page)
    },

    //显示编辑界面
    handleEdit: function (index, row) {
      this.editFormVisible = true
      this.orderInfo = row;
      this.getOrderDetails()
    },


    // 关闭编辑、增加弹出框
    closeDialog(formName) {
      this.editFormVisible = false
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}

.userRole {
  width: 100%;
}
</style>

 
 

 